package com.zhouheng.springbootconverter.controller;

import com.zhouheng.springbootconverter.dto.ConverterDto;
import com.zhouheng.springbootconverter.vo.DateVo;
import com.zhouheng.springbootconverter.vo.LocalDateTimeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;

/**
 * 格式转换控制层
 *
 * @author 周恒
 * @date 20200421 16:27:13
 * @since v1.0
 */
@Api(tags = "格式转换")
@RestController
@RequestMapping("/converter")
public class ConverterConfigController {

    @ApiOperation("测试全局LocalDateTime 和 String jackson转换")
    @PostMapping(value = "/localDateTime")
    public ConverterDto localDateTime(@RequestBody LocalDateTimeVo localDateTimeVo) {
        System.out.println(localDateTimeVo.getLocalDateTime());
        return new ConverterDto(LocalDateTime.of(LocalDate.of(1993,2,28), LocalTime.MIN));
    }

    @ApiOperation("测试全局Date 和 String jackson转换")
    @PostMapping(value = "/date")
    public ConverterDto date(@RequestBody DateVo dateVo) {
        System.out.println(dateVo.getDate());
        return new ConverterDto(new Date());
    }

}
